package vampirism.core.shared;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Creator {

	public static Random rand = new Random(Network.seed);
	
	public static Bullet createBullet(Body body, float rotation){
		Bullet bullet = new Bullet();
		
		bullet.damage = 4;
		bullet.sourceId = body.index;
		
		bullet.tier = 0;
		bullet.type = body.type;
		
		bullet.pos.x = body.pos.x;
		bullet.pos.y = body.pos.y;
		
		bullet.timeCreated = System.currentTimeMillis();
		bullet.lifeTime = (long)330;
		bullet.lastMoveTime = System.currentTimeMillis();
		
		bullet.rotation = rotation;
		
		return bullet;
	}
	
	public static Player createPlayer(int accountId, int accountPlayerNum, String name, byte type){
		Player player = new Player();
		player.accountId = accountId;
		player.accountPlayerNum = accountPlayerNum;
		player.index = -1;// player is still currently offline
		player.name = name;
		player.type = type;
		player.pos.x = rand.nextInt(64) - rand.nextInt(64);
		player.pos.y = rand.nextInt(64) - rand.nextInt(64);
		player.lastMoveTime = System.currentTimeMillis();
		player.pos.width = 8;
		player.pos.height = 8;
		player.initStats();
		
		return player;
	}

	public static List<Biome> createBiomes(Tile[][] map) {
		
		List<Biome> biomes = new ArrayList<Biome>();
		
		for(int i = 0; i <= Network.biomeCount; i++)
			biomes.add(new Biome((short)i));
		
		//Each tile belongs to some biome
		//Each biome may or may not be empty (but not null)
		
		for(int i = 0; i < Network.MAP_W; i++){
			for(int j = 0; j < Network.MAP_H; j++){
				biomes.get(map[i][j].biomeNum).tiles.add(map[i][j]);
			}
		}
		
		for(int i = 0; i <= Network.biomeCount; i++)
			biomes.get(i).setNpcCount();
			
			
		return biomes;
	}
}
